<%@include  file="/WEB-INF/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
	
     <!-- 用户列表  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">商品管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->

		<a href="#" class="btn btn-primary"  data-toggle="modal" 
		           data-target="#newCateDialog"  onclick="clearuser()">新建</a>
		
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">商品信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>序号</th>
								<th>商品名</th>
								<th>价格</th>
								<th>销售量</th>
								<th>图片</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							
								<c:forEach items="${glist}" var="u" varStatus="i">
								<tr>
									<td>${u.produce_id }</td>
									<td>${u.produce_name }</td>
									<td>${u.produce_price }</td>
									<td>${u.produce_sales }</td>
									<td><img src="${pageContext.request.contextPath }${u.produce_pic}" width="80px" height="70px"/></td>
									<td>
									<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#produceEditDialog"
									onclick="editProduce(${u.produce_id})">修改</a>
										<a href="${pageContext.request.contextPath }/user/delP.action?produce_id=${u.produce_id }" class="btn btn-danger btn-xs" role="button" onclick="JavaScript:return confirm('确实要删除该用户信息吗？')">删除</a>
									</td>
								</tr>
								</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<pagebar:page url="${pageContext.request.contextPath }/goods/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 用户列表  end-->
</div>

	<!-- 创建用户模态框 -->
	<form class="form-horizontal" id="new_produce_form">
<div class="modal fade" id="newCateDialog" tabindex="-1" role="dialog"
	 aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建商品信息</h4>
			</div>
			<div class="modal-body">

					<div class="form-group">
						<label for="new_producename" class="col-sm-2 control-label">
							商品名：
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_producename" placeholder="请输入价格" name="produce_name" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_price" class="col-sm-2 control-label">新价格：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_price" placeholder="请输入价格" name="produce_price" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_sales" class="col-sm-2 control-label">销售量：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_sales" placeholder="请输入价格" name="produce_sales" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_pic" class="col-sm-2 control-label">图片：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_pic" placeholder="请输入价格" name="produce_pic" />
						</div>
					</div>
					
					


			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="addProduce()">创建用户</button>
			</div>

		</div>
	</div>
</div>
</form>produceEditDialog
<form class="form-horizontal" id="new1_produce_form">
<div class="modal fade" id="produceEditDialog" tabindex="-1" role="dialog"
	 aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建商品信息</h4>
			</div>
			<div class="modal-body">

					<div class="form-group">
						<label for="new_producename" class="col-sm-2 control-label">
							商品名：
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_producename" placeholder="请输入价格" name="produce_name" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_price" class="col-sm-2 control-label">新价格：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_price" placeholder="请输入价格" name="produce_price" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_sales" class="col-sm-2 control-label">销售量：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_sales" placeholder="请输入价格" name="produce_sales" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_pic" class="col-sm-2 control-label">图片：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_pic" placeholder="请输入价格" name="produce_pic" />
						</div>
					</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateProduce()">创建用户</button>
				
			</div>
			<div class="form-group">
				<div class="col-sm-10">
					<input type="text" class="form-control" id="produce_id" placeholder="请输入修改的id" name="produce_id" />
				</div>
			</div>
		</div>
	</div>
</div>
</form>
	
	
	
	<!-- 引入js文件 -->
	<!-- jQuery -->
	<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>js/sb-admin-2.js"></script>
	<!-- 编写js代码 -->
	
	<script type="text/javascript">
	//清空新建用户窗口中的数据
	function clearuser() {
	    $("#new_producename").val("");
	    $("#new_produceprice").val("");
	}
	// 创建用户
	function addProduce() {
	alert("ccc");
	$.post("${pageContext.request.contextPath}/user/addProduce.action",
			$("#new_produce_form").serialize(),function(data){
				if(data =="OK"){
					alert("用户创建成功！");
					window.location.reload();
				}else{
					alert("用户创建失败！");
					window.location.reload();
				}

			});
}
	// 通过id获取修改的用户信息
	function editProduce(produce_id) {
		$.post("${pageContext.request.contextPath}/user/showProduce.do",{"produce_id":produce_id},function(data){
	         $("#edit_producename").val(data.produce_name);
	         $("#edit_produceprice").val(data.produce_price);
	         $("#edit_produceid").val(data.produce_id);
	         //$("#form_username").show();
             //$("#form_userpass").show();
             //$("select option[value='"+data.parentid+"']").attr("selected", "selected");  
		},"json");
	}
    // 执行修改用户操作
	function updateProduce() {
    	alert("11");
		$.post("${pageContext.request.contextPath}/user/update.action",
				$("#new1_produce_form").serialize(),function(data){
			if(data =="OK"){
				alert("用户信息更新成功！");
				window.location.reload();
			}else{
				alert("用户信息更新失败！");
				window.location.reload();
			}
		});
	}
</script>



 <%@include  file="/WEB-INF/footer.jsp"%>